<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title><!--{if $source_array}-->修改<!--{else}-->添加<!--{/if}-->图片资源位</title>
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_pic.tpl'}-->
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">

        <h2 style="" class="tal">正在操作：<!--{if $source_array}-->修改<!--{else}-->添加<!--{/if}-->图片资源位</h2>

        <div class="items2">

            <!--{if !$source_array}-->
            <div class="select-box">
                <div onclick="source.change(4);">商品资源位</div>
                <div class="selected" onclick="source.change(5);">图片资源位</div>
                <div onclick="source.change(9);">富文本资源位</div>
                <div onclick="source.change(10);">文本资源位</div>
            </div>
            <!--{/if}-->

            <div>
                <form id="source_form" onsubmit="return false;">
                    <table>
                        <tbody>
                        <tr>
                            <td class="tar" width="150">资源位分类：</td>
                            <td width="500">

                                <select id="parent_id" name="parent_id" style="width: 250px;">
                                    <!--{foreach from=$source_category_array item=source}-->

                                        <!--{if $source.parent_id == 0}-->
                                            <option value="<!--{$source.id}-->" disabled="disabled"><!--{$source.title}--></option>
                                        <!--{else}-->
                                            <option value="<!--{$source.id}-->"><!--{$source.title}--></option>
                                        <!--{/if}-->

                                        <!--{foreach from=$source.list item=list}-->
                                            <option value="<!--{$list.id}-->"<!--{if $source_array.source_category_id == $list.id}--> selected="selected" <!--{/if}-->>&nbsp;&nbsp;<!--{$list.title}--></option>
                                        <!--{/foreach}-->

                                    <!--{/foreach}-->
                                </select>
                                <font color="red">*</font>

                            </td>
                            <td width="*" rowspan="5">
                                <div id="show_img" style="border: 1px solid #CCCCCC;height: 185px;margin: 0 auto;width: 185px;">
                                    <!--{if $source_array.pictureLink}-->
                                    <a class="fancybox" href="<!--{$source_array.piclink}-->">
                                        <img height="185px" width="185px" src="<!--{$source_array.piclink}-->" />
                                    </a>
                                    <!--{/if}-->
                                </div>
                                <input type="hidden" name="parnet_id" value="<!--{$source_array.source_category_id}-->" />
                                <input type="hidden" name="promotion_img" id="promotion_img" value="<!--{$source_array.pictureLink}-->" />
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">资源位标题：</td>
                            <td>
                                <input type="text" value="<!--{$source_array.source_title}-->" name="title" id="title" style="width: 400px;" />
                                <font class="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">资源位简述：</td>
                            <td>
                                <input type="text" value="<!--{$source_array.source_brief}-->" name="brief" id="brief" style="width: 400px;" />
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">资源位URL：</td>
                            <td>
                                <input type="text" value="<!--{$source_array.urlLink}-->" name="url" id="url" style="width: 400px;" />
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">使用标志：</td>
                            <td>
                                <!--{if $source_array}-->
                                    <input type="radio" value="1" name="useFlg"<!--{if $source_array.useFlg == 1}--> checked="checked"<!--{/if}--> /> 启用
                                    <input type="radio" value="0" name="useFlg"<!--{if $source_array.useFlg == 0}--> checked="checked"<!--{/if}--> /> 禁用
                                <!--{else}-->
                                    <input type="radio" value="1" name="useFlg" checked="checked" /> 启用
                                    <input type="radio" value="0" name="useFlg" /> 禁用
                                <!--{/if}-->
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">是否打开新页面：</td>
                            <td>
                                <!--{if $source_array}-->
                                    <input type="radio" value="1" name="openPage"<!--{if $source_array.openPage == 1}--> checked="checked"<!--{/if}--> /> 是
                                    <input type="radio" value="0" name="openPage"<!--{if $source_array.openPage == 0}--> checked="checked"<!--{/if}--> /> 否
                                <!--{else}-->
                                    <input type="radio" value="1" name="openPage" checked="checked" /> 是
                                    <input type="radio" value="0" name="openPage" /> 否
                                <!--{/if}-->
                                <font color="red">*</font>
                                <input type="hidden" name="id" value="<!--{$source_array.source_id|default:0}-->" />
                            </td>
                            <td class="tac">
                                <input type="button" value="上传图片" class="btn" onclick="source.uploadImg();" />
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div>
                        <textarea name="description" id="description" style="width:100%;height:400px;visibility:hidden;"><!--{$source_array.description}--></textarea>
                    </div>
                </form>
            </div>

        </div>
    </div>


    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="source.check();" value="<!--{if $source_array}-->修改<!--{else}-->添加<!--{/if}-->资源位" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn cancel_b" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>



</div>

<script type="text/javascript">
	window.editor = KindEditor.create("#description");
	
    var source = {

        category_id: <!--{$category_id|default:0}-->,

        source_id: <!--{$source_array.source_id|default:0}-->,

        //检查数据
        check: function() {
        	
        	editor.sync();
        	
            this.dt = E.getFormValues("source_form");
            
            var error_msg = "";
            if (this.dt.title == "")
                error_msg += "资源位标题不能为空<br />";
            if (this.dt.url == "" && this.dt.content == "")
                error_msg += "资源位URL和资源位内容不能同时为空<br />";
            if (error_msg != "")
                E.alert(error_msg);
            else
                E.confirm("您确认要<!--{if $source_array}-->修改<!--{else}-->添加<!--{/if}-->资源位信息吗？", "source.add");
        },

        //保存资源位信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/content/source.ajax?operFlg=4",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        if (source.category_id == 0)
                            E.opener("source.load");
                        if (source.source_id == 0)
                            E.alert(result_obj.message, 2, "E.refresh");
                        else
                            E.alert(result_obj.message, 2, "E.closeWindows");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //上传图片
        uploadImg: function() {
            E.open("/quanliadmin/app/uploads/imageUpload.php?uploadPara=16", "上传", {height: 50, width: 600, top: 280, left: 300});
        },

        //切换标签
        change: function(operFlg) {
            if (this.category_id) {
                self.location = "/quanliadmin/app/content/source.pscript?operFlg=" + operFlg + "&category_id=" + this.category_id;
            } else {
                self.location = "/quanliadmin/app/content/source.pscript?operFlg=" + operFlg;
            }
        }

    };

    function getUploadFileName(upload_fileName) {
        var list_html = "<a class=\"fancybox\" href=\"/quanliadmin/docroot/images/promotion/" + upload_fileName + "\"><img height=\"185px\" width=\"185px\" src=\"/quanliadmin/docroot/images/promotion/" + upload_fileName + "\" /></a>";
        $("#show_img").html(list_html);
        $("#promotion_img").val(upload_fileName);
    }

    $(document).ready(function() {
        $('.fancybox').fancybox();
    });


</script>

</body>

</html>
